/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.aratuk.servico;

import br.com.aratuk.modelo.Aposta;
import br.com.aratuk.modelo.Jogo;
import br.com.aratuk.modelo.Linha;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author roniere
 */
@Stateless
public class ApostaServico extends ServicoGenerico<Aposta> {

    public ApostaServico() {
        super(Aposta.class);
    }
    
    
    public List<Aposta> apostaPorJogo(Jogo jogo){
        String sql = "SELECT a FROM Aposta a JOIN a.jogo j WHERE j.id = :id";
        
        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", jogo.getId());
        return query.getResultList();
    }
    
    
    public List<Linha> jsonToAposta(String data){
        data = data.replace("numeros", "numero");
        data = data.replace("bola_extra", "bolasExtra");
        Gson gson = new GsonBuilder().setDateFormat("dd/MM/yyyy").create();
        return gson.fromJson(data, new TypeToken<List<Linha>>(){}.getType());
    }
    
    
}
